﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using MyBBSWebApi.Models;
using MyBBSWebApi.BLL;

namespace MyBBSWebApi.Controllers
{
    //[Route("api/[controller]/[action]")]
    [Route("[controller]")]    //restful
    [ApiController]
    public class LoginController : ControllerBase
    {
        private readonly IUserBll _userBll;
        public LoginController(IUserBll userBll)
        {
            _userBll = userBll;
        }

        [HttpGet]
        public List<Users> GetAll()
        {
            List<Users> userList = _userBll.GetAll();
            return userList;
        }


        [HttpGet("{userNo}/{password}")]
        public Users Get(string userNo, string password)
        {
            Users user = _userBll.CheckLogin(userNo, password);
            return user;
        }



        [HttpPost]
        public string Insert(string userNo, string userName, int userLevel, string password)
        {
            return _userBll.AddUser(userNo, userName, userLevel, password);
        }


        [HttpPut]
        public string Update(int id, string userNo, string userName, string password, int? userLevel)
        {
            return _userBll.UpdateUser(id, userNo, userName, password, userLevel);
        }

        [HttpDelete]
        public string Delete(int ID)
        {
            return _userBll.RemoveUser(ID);
        }


    }
}
